package cc.linker.steplink.crm.configuration;


import cc.linker.steplink.crm.commons.Constants;
import cc.linker.steplink.crm.web.filter.CorsFilter;
import cc.linker.steplink.crm.web.interceptor.UserLoginInterceptor;
import cc.linker.steplink.crm.web.interceptor.XbAccessInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * web层配置
 *
 * @author zhaomengwei
 */
@Configuration("webConfiguration")
public class WebConfiguration extends WebMvcConfigurerAdapter {

    @Value("${cors.allowOrgin}")
    private String allowOrgin;
    @Value("${spring.profiles.active}")
    private String profiles;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 过滤器注册
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new CorsFilter(allowOrgin, profiles));
        registration.addUrlPatterns("/*");
        registration.setName("corsFilter");
        registration.setOrder(0);
        return registration;

    }

    /**
     * 拦截器实现
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/hello")
                .excludePathPatterns("/helloworld")
                .excludePathPatterns("/getOrgInfoByLogin")
                .excludePathPatterns("/test")
                .excludePathPatterns("/sync/**")
                .excludePathPatterns("/personal/**")
                .excludePathPatterns("/task/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/personalcenter/**")
                .excludePathPatterns("/articledata/h5/**")
                .excludePathPatterns("/label/getlabellist")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/jsapi/**")
                .excludePathPatterns("/mall/**")
                .excludePathPatterns("/recommend/**")
                .excludePathPatterns("/h5/**")
                .excludePathPatterns("/shop/order/getExpress")
                .excludePathPatterns("/mallboom/**")
                .excludePathPatterns("/wxshare/**")
                .excludePathPatterns("/user/ifSales")
                .excludePathPatterns("/user/getUserPageList")
                .excludePathPatterns("/user/getUserBehaviorList")
                .excludePathPatterns("/user/getUserInfo")
                .excludePathPatterns("/user/alipayUserSave")
                .excludePathPatterns("/user/appUserSave")
                .excludePathPatterns("/customer/alipayOrders")
                .excludePathPatterns("/shop/group/listAll")
                .excludePathPatterns("/config/getwxtoken")
                .excludePathPatterns("/config/getshorturl")
                .excludePathPatterns("/shop/goods/listPaging")
                .excludePathPatterns("/eventmsg/**")
                .excludePathPatterns("/basic/**")
                .excludePathPatterns("/acs/merchantsaler/**")
                .excludePathPatterns("/acs/merchantwallet/**")
                .excludePathPatterns("/acs/paycallback*")
                .excludePathPatterns("/acs/refundcallback")
                .excludePathPatterns("/platform/paySetting")
                .excludePathPatterns("/platform/platformlist")
                .excludePathPatterns("/platform/getpaysetting")
                .excludePathPatterns("/platform/bussinessaccountlist")
                .excludePathPatterns("/wxshare/api/getlimitqrcode")
                .excludePathPatterns("/wxshare/addcactivelog")
                .excludePathPatterns("/acs/joinAgent/**")
                .excludePathPatterns("/applets/login")
                .excludePathPatterns("/app/login")
                .excludePathPatterns("/shop/goods/mediaProductShared")
                .excludePathPatterns("/shop/goods/mediaProductChoose")
                .excludePathPatterns("/shop/order/externalDelivery")
                .excludePathPatterns("/crmhelper/trans")
                .excludePathPatterns("/dong/paycallback")
                .excludePathPatterns("/acs/merchantinfo/changestatus")
                .excludePathPatterns("/applets/login")
                .excludePathPatterns("/customer/service/setCustomer")
                .excludePathPatterns("/liveGoods/**")
                .excludePathPatterns("/shop/goods/uploadPicture")
                .excludePathPatterns("/customer/group/userOpenIdList")
                .excludePathPatterns("/updateAccountMoneyDayTasksToDo")
                .excludePathPatterns("/personal/loginByCustomerId")
                .excludePathPatterns("/customer/group/openList")
                .excludePathPatterns("/acs/transferRefundCallBack")
                .excludePathPatterns("/auth/applicationAuth")
                .excludePathPatterns("/shop/goods/flushGoodsCache")
                .excludePathPatterns("/ossUpload/**")
                .excludePathPatterns("/form/login")
                .excludePathPatterns("/acs/xbMerchant/exportTransactionDetails")
                .excludePathPatterns("/shop/order/exportmallslist")
                .excludePathPatterns("/shop/order/exportList")
                .excludePathPatterns("/pc/coupon/exportcoupondata")
                .excludePathPatterns("/pc/coupon/exportcouponlist")
                .excludePathPatterns("/achievement/exportlist")
                .excludePathPatterns("/integral/goods/exportExchangelist")
                .excludePathPatterns("/survival/exportlist")
                .excludePathPatterns("/pc/publish/export")
                .excludePathPatterns("/pc/publish/exportlist")
                .excludePathPatterns("/pc/publish/exoprtjoincustomerlist")
                .excludePathPatterns("/pc/publish/export")
                .excludePathPatterns("/acs/merchantinfo/exportsalerpromotersonlist")
                .excludePathPatterns("/acs/merchantinfo/exportGetuserlist")
                .excludePathPatterns("/redirect/**")
                .excludePathPatterns("/withdraw/exportwithdrawlist")
                 .excludePathPatterns("/h5/form/log/add");
    }

}
